package com.laibo.core.test;

import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.BodyContentHandler;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class PDF {

    private static void extractContent(File file) {
        try (PDDocument doc = PDDocument.load(file)) {
            PDDocumentInformation pdDocumentInformation = doc.getDocumentInformation();
            PDFTextStripper stripper = new PDFTextStripper();
            stripper.setStartPage(1);
            stripper.setEndPage(doc.getNumberOfPages());
            String title = pdDocumentInformation.getTitle();
            String keywords = pdDocumentInformation.getKeywords();
            String author = pdDocumentInformation.getAuthor();
            System.out.println(title + '\n' + keywords + '\n' + author);
            String text = stripper.getText(doc);
            System.out.println();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {


        extractContent(new File("C:\\Users\\YouAreJ\\Desktop\\es\\upload.pdf"));
    }
}
